package com.kai.service.data.response.user;

import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.kai.service.enums.GenderEnum;
import com.kai.service.user.entity.User;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.util.Date;
import java.util.Objects;

@Data
public class UserInfoResponse {

    public UserInfoResponse(User user) {
        BeanUtils.copyProperties(user, this);
        this.genderName = GenderEnum.getDescByCode(user.getGender());
        this.age = Objects.isNull(user.getBirthday()) ? null : DateUtil.age(user.getBirthday(), new Date());
    }

    /**
     * 用户id
     */
    private Long id;

    /**
     * 账号
     */
    private String username;

    /**
     * 昵称
     */
    private String nickName;

    /**
     * 头像url
     */
    private String imgUrl;

    /**
     * 性别, 0-未知 1-男，2-女
     */
    private Integer gender;

    /**
     * 性别
     */
    private String genderName;

    /**
     * 年龄
     */
    private Integer age;

    /**
     * 生日
     */
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date birthday;

    /**
     * 邮箱
     */
    private String email;

}
